In [2]:
import matplotlib.pyplot as plt
In [3]:
import graph_tool.all as gt

1 - Rede das bitcoin sla oq

In [6]:
g = gt.load_graph_from_csv("Datasets/soc-sign-bitcoinotc.csv.gz")
In [19]:
vtxs = 0
for v in g.vertices():
    vtxs += 1
    
edgs = 0
for e in g.edges():
    edgs += 1
In [20]:
vtxs, edgs
Out[20]:
(5881, 35592)
In [21]:
gt.graph_draw(g)
Out[21]:
<VertexPropertyMap object with value type 'vector<double>', for Graph 0x7f7df0665220, at 0x7f7df0fc83a0>

Estudo dos graus

máximo, mínimo, média, mediana, desvio padrão, e distribuição empírica

In [39]:
H = gt.vertex_hist(g, "out")
In [45]:
qtds, degs = H
In [55]:
plt.plot(qtds)
Out[55]:
[<matplotlib.lines.Line2D at 0x7f7de6bdb760>]
In [57]:
plt.hist(H);
In [31]:
gt.vertex_average(g,"out")
Out[31]:
(12.104063934704982, 0.49937172589735424)
In [59]:
%timeit gt.distance_histogram(g)
1.22 s ± 77.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

Distancia

In [63]:
DistH =  gt.distance_histogram(g)
DistH
Out[63]:
[array([0.0000000e+00, 4.2984000e+04, 2.4057780e+06, 1.3941952e+07,
        1.4491508e+07, 3.2089060e+06, 3.8557400e+05, 3.1516000e+04,
        1.5020000e+03, 3.6000000e+01]),
 array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10], dtype=uint64)]
In [66]:
plt.plot(DistH[0]);

Componentes

In [71]:
gt.label_components(g)
Out[71]:
(<VertexPropertyMap object with value type 'int32_t', for Graph 0x7f7df0665220, at 0x7f7de65c55e0>,
 array([5875,    2,    2,    2], dtype=uint64))
In [76]:
tree = gt.min_spanning_tree(g)
gt.graph_draw(g, edge_color=tree)
Out[76]:
<VertexPropertyMap object with value type 'vector<double>', for Graph 0x7f7df0665220, at 0x7f7de656cd00>
In [78]:
g.set_edge_filter(tree)
gt.graph_draw(g)
Out[78]:
<VertexPropertyMap object with value type 'vector<double>', for Graph 0x7f7df0665220, at 0x7f7de65fc760>
In [79]:
bv, be = gt.betweenness(g)
be.a /= be.a.max() / 5
In [80]:
gt.graph_draw(g, vertex_fill_color=bv, edge_pen_width=be)
Out[80]:
<VertexPropertyMap object with value type 'vector<double>', for Graph 0x7f7df0665220, at 0x7f7de6534850>

astro-ph power dolphins

In [4]:
g = gt.collection.data["dolphins"]
In [6]:
gt.graph_draw(g)
Out[6]:
<VertexPropertyMap object with value type 'vector<double>', for Graph 0x7f31aa46c3a0, at 0x7f318b885460>
In [8]:
g = gt.collection.data["power"]
In [10]:
gt.graph_draw(g)
Out[10]:
<VertexPropertyMap object with value type 'vector<double>', for Graph 0x7f318caae5e0, at 0x7f31aa46c280>
In [11]:
g = gt.collection.data["astro-ph"]
In [12]:
gt.graph_draw(g)
Out[12]:
<VertexPropertyMap object with value type 'vector<double>', for Graph 0x7f318b885e50, at 0x7f31c13cfd60>